package cn.edu.ujn.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import cn.edu.ujn.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import cn.edu.ujn.system.domain.FStudent;
import cn.edu.ujn.system.mapper.FExcuseMapper;
import cn.edu.ujn.system.domain.FExcuse;
import cn.edu.ujn.system.service.IFExcuseService;
import cn.edu.ujn.common.core.text.Convert;

/**
 * 请假信息管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-11-22
 */
@Service
public class FExcuseServiceImpl implements IFExcuseService 
{
    @Autowired
    private FExcuseMapper fExcuseMapper;

    /**
     * 查询请假信息管理
     * 
     * @param excuseId 请假信息管理主键
     * @return 请假信息管理
     */
    @Override
    public FExcuse selectFExcuseByExcuseId(Long excuseId)
    {
        return fExcuseMapper.selectFExcuseByExcuseId(excuseId);
    }

    /**
     * 查询请假信息管理列表
     * 
     * @param fExcuse 请假信息管理
     * @return 请假信息管理
     */
    @Override
    public List<FExcuse> selectFExcuseList(FExcuse fExcuse)
    {
        return fExcuseMapper.selectFExcuseList(fExcuse);
    }

    /**
     * 新增请假信息管理
     * 
     * @param fExcuse 请假信息管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertFExcuse(FExcuse fExcuse)
    {
        int rows = fExcuseMapper.insertFExcuse(fExcuse);
        insertFStudent(fExcuse);
        return rows;
    }

    /**
     * 修改请假信息管理
     * 
     * @param fExcuse 请假信息管理
     * @return 结果
     */
    @Transactional
    @Override
    public int updateFExcuse(FExcuse fExcuse)
    {
        fExcuseMapper.deleteFStudentByStudentId(fExcuse.getExcuseId());
        insertFStudent(fExcuse);
        return fExcuseMapper.updateFExcuse(fExcuse);
    }

    /**
     * 批量删除请假信息管理
     * 
     * @param excuseIds 需要删除的请假信息管理主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteFExcuseByExcuseIds(String excuseIds)
    {
        fExcuseMapper.deleteFStudentByStudentIds(Convert.toStrArray(excuseIds));
        return fExcuseMapper.deleteFExcuseByExcuseIds(Convert.toStrArray(excuseIds));
    }

    /**
     * 删除请假信息管理信息
     * 
     * @param excuseId 请假信息管理主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteFExcuseByExcuseId(Long excuseId)
    {
        fExcuseMapper.deleteFStudentByStudentId(excuseId);
        return fExcuseMapper.deleteFExcuseByExcuseId(excuseId);
    }

    /**
     * 新增学生信息管理信息
     * 
     * @param fExcuse 请假信息管理对象
     */
    public void insertFStudent(FExcuse fExcuse)
    {
        List<FStudent> fStudentList = fExcuse.getFStudentList();
        Long excuseId = fExcuse.getExcuseId();
        if (StringUtils.isNotNull(fStudentList))
        {
            List<FStudent> list = new ArrayList<FStudent>();
            for (FStudent fStudent : fStudentList)
            {
                fStudent.setStudentId(excuseId);
                list.add(fStudent);
            }
            if (list.size() > 0)
            {
                fExcuseMapper.batchFStudent(list);
            }
        }
    }
}
